package com.lin.jfreeChart;

import java.awt.Font;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

import com.opensymphony.xwork2.ActionSupport;

public class BarChart3DAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JFreeChart chart;

	public JFreeChart getChart() {
		chart = ChartFactory.createBarChart3D("图书销量统计图", "图书", "销量", getDataSet(),

				PlotOrientation.VERTICAL, false, false, false);

		chart.setTitle(new TextTitle("图书销量统计图", new Font("黑体", Font.ITALIC, 22)));
		CategoryPlot plot = (CategoryPlot) chart.getPlot();

		CategoryAxis categoryAxis = plot.getDomainAxis();

		categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 22));

		categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
		categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 18));

		NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();

		numberAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 22));
		return chart;
	}

	private static CategoryDataset getDataSet() {

		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		dataset.addValue(47000, "", "Java讲义");
		dataset.addValue(38000, "", "Java EE企业实战");
		dataset.addValue(31000, "", "Ajax讲义");
		dataset.addValue(29000, "", "Struts 2权威指南");
		dataset.addValue(25000, "", "XML讲义");
		return dataset;
	}
}
